﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.fminutes.vinciDll {
    import flash.events.*;
    import flash.net.*;

    public class MultiLoader extends EventDispatcher {

        protected var loader:URLLoader;
        public var fileArr:Array;
        private var _pause:Boolean;
        public var index:int = 0;
        private var totalSize:int = 0;
        private var realProgress:Boolean = false;
        private var ignoreIOerror:Boolean = false;

        public function MultiLoader(){
            this.loader = new URLLoader();
            this.loader.dataFormat = URLLoaderDataFormat.BINARY;
            this.loader.addEventListener(Event.COMPLETE, this.onComp);
            this.loader.addEventListener(IOErrorEvent.IO_ERROR, this.ioError);
            this.loader.addEventListener(ProgressEvent.PROGRESS, this.onProgress);
        }
        public function load(_arg1:Array, _arg2:Boolean=false, _arg3:Boolean=false):void{
            this.fileArr = _arg1.concat();
            this.realProgress = _arg2;
            this.ignoreIOerror = _arg3;
            if (_arg2){
                this.totalSize = this.getTotalSize(_arg1);
            };
            this.loadItem();
        }
        public function get fileArray():Array{
            return (this.fileArr);
        }
        private function getTotalSize(_arg1:Array):int{
            var _local2:int;
            var _local3:int;
            while (_local3 < _arg1.length) {
                _local2 = (_local2 + int((_arg1[_local3] as DllFileObject).size));
                _local3++;
            };
            return (_local2);
        }
        private function getLoadedSize(_arg1:Array, _arg2:int):int{
            var _local3:int;
            var _local4:int;
            while (_local4 < _arg2) {
                _local3 = (_local3 + int((_arg1[_local4] as DllFileObject).size));
                _local4++;
            };
            return (_local3);
        }
        protected function loadItem():void{
            var _local1:URLRequest = (this.fileArr[this.index] as DllFileObject).urlRequest;
            this.loader.load(_local1);
            (this.fileArr[this.index] as DllFileObject).status = DllFileObject.LOADING;
        }
        private function onComp(_arg1:Event):void{
            this.currentComp(this.index, _arg1.currentTarget.data);
        }
        protected function next():void{
            this.index = (this.index + 1);
            if (this.index >= this.fileArr.length){
                this.allComp();
            } else {
                this.loadItem();
            };
        }
        protected function reload():void{
            if (this.index >= this.fileArr.length){
                this.allComp();
            } else {
                this.loadItem();
            };
        }
        protected function currentComp(_arg1:int, _arg2:Object):void{
            (this.fileArr[_arg1] as DllFileObject).result = _arg2;
            this.next();
        }
        protected function allComp():void{
            dispatchEvent(new MultiLoaderEvent(MultiLoaderEvent.COMPLETE, this.fileArr));
        }
        private function ioError(_arg1:IOErrorEvent):void{
            var _local2:FileObject;
            if (this.ignoreIOerror){
                _local2 = (this.fileArr[this.index] as DllFileObject);
                dispatchEvent(new MultiLoaderEvent(MultiLoaderEvent.IO_ERROR, _local2));
            } else {
                (this.fileArr[this.index] as DllFileObject).result = null;
                this.next();
            };
        }
        private function onProgress(_arg1:ProgressEvent):void{
            var _local2:int;
            var _local3:int;
            if (this.realProgress){
                _local2 = (this.getLoadedSize(this.fileArr, this.index) + _arg1.bytesLoaded);
                _local3 = this.totalSize;
            } else {
                _local2 = (((this.index / this.fileArr.length) + ((_arg1.bytesLoaded / _arg1.bytesTotal) * (1 / this.fileArr.length))) * 100);
                _local3 = 100;
            };
            var _local4:Object = {};
            _local4.progress = Math.round(((_local2 / _local3) * 100));
            var _local5:MultiLoaderEvent = new MultiLoaderEvent(MultiLoaderEvent.PROGRESS, _local4);
            dispatchEvent(_local5);
        }
        public function get pause():Boolean{
            return (this._pause);
        }
        public function set pause(_arg1:Boolean):void{
            this._pause = _arg1;
            if (!this._pause){
                this.next();
            };
        }

    }
}//package com.fminutes.vinciDll 
